package com.qiniu.githubdata.mapper;

import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;

import com.qiniu.githubdata.entity.neo.DeveloperNode;
import org.springframework.stereotype.Repository;

@Repository
public interface DeveloperNodeRepository extends Neo4jRepository<DeveloperNode, Long> {
    @Query("""
        MATCH (d:Developer)-[c:CONTRIBUTED_TO]->(r:Repository)
        WHERE d.id = $developerId
        RETURN sum(c.contributionScore * r.importance) as baseScore
    """)
    Double calculateBaseContributionScore(@Param("developerId") Long developerId);
    
    @Query("""
        MATCH (d:Developer)<-[:FOLLOWS]-(f:Developer)
        WHERE d.id = $developerId
        WITH d, count(f) as followerCount, avg(f.talentRank) as avgFollowerRank
        RETURN 1 + log10(1 + followerCount) * (1 + avgFollowerRank/10) as multiplier
    """)
    Double calculateNetworkMultiplier(@Param("developerId") Long developerId);
    
    @Query("""
        MATCH (d:Developer)-[c:CONTRIBUTED_TO]->(r:Repository)
        WHERE d.id = $developerId
        WITH d, count(DISTINCT r.language) as languageCount
        RETURN 0.1 * log10(1 + languageCount) as diversityBonus
    """)
    Double calculateProjectDiversityBonus(@Param("developerId") Long developerId);
    
    @Query("""
        MATCH (d:Developer)
        WHERE d.id = $developerId
        SET d.talentRank = $talentRank
    """)
    void updateTalentRank(@Param("developerId") Long developerId, @Param("talentRank") Double talentRank);
}